package com.sky.controller.user;

import com.sky.entity.Dish;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 用户端菜品浏览接口
 */
@RestController("userDishController")
@RequestMapping("/user/dish")
@Api(tags = "用户端-菜品浏览接口")
@Slf4j
public class DishController {
    
    @Autowired
    private DishService dishService;
    
    /**
     * 根据分类id查询菜品列表
     * @param categoryId 分类id
     * @return 菜品列表，包含口味信息
     */
    @GetMapping("/list")
    @ApiOperation("根据分类id查询菜品")
    public Result<List<DishVO>> list(Long categoryId) {
        log.info("用户端根据分类id查询菜品: {}", categoryId);
        // 用户端查询需要返回包含口味信息的菜品VO列表
        List<DishVO> dishVOList = dishService.listWithFlavor(categoryId);
        return Result.success(dishVOList);
    }
    
    /**
     * 根据菜品id查询菜品详情
     * @param id 菜品id
     * @return 菜品详情，包含口味信息
     */
    @GetMapping("/detail/{id}")
    @ApiOperation("查询菜品详情")
    public Result<DishVO> detail(@PathVariable Long id) {
        log.info("用户端查询菜品详情: {}", id);
        DishVO dishVO = dishService.getByIdWithFlavor(id);
        return Result.success(dishVO);
    }
}